<template>
    <div>

        <el-form :inline="true" :model="medbuy" label-width="70px">
            <el-form-item label="药品名称">
                <el-input placeholder="请输入查询的药品名称" v-model="medbuy.mbname"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="list()"><i class="el-icon-search">查询</i></el-button>
                <el-button type="info" @click="reset()"><i class=" el-icon-refresh">重置</i></el-button>
            </el-form-item>
        </el-form>

        <el-table :data="medbuyList" border stripe style="width: 100%">
            <el-table-column prop="mbid" label="采购编号">
            </el-table-column>
            <el-table-column prop="mbname" label="药品名称">
            </el-table-column>
            <el-table-column prop="mbnum" label="药品采购数量">
            </el-table-column>
            <el-table-column prop="mbcost" label="药品采购价">
            </el-table-column>
            <el-table-column prop="mbprotime" label="药品生产日期">
            </el-table-column>
            <el-table-column prop="buytime" label="采购入库时间">
            </el-table-column>
        </el-table>

        <!-- 分页功能 -->
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="pageInfo.pageNum" :page-sizes="[5, 10, 15, 20]" :page-size="pageInfo.pageSize"
            layout="total, sizes, prev, pager, next, jumper" :total="pageInfo.total">
        </el-pagination>
    </div>
</template>

<script>

export default {
    data() {
        return {
            medbuyList: [],
            pageInfo: {
                pageNum: 1,
                pageSize: 5
            },
            medbuy: {}, //查询定义
        };
    },

    mounted() {
        this.list();
    },

    methods: {
        // buysearch() {  //    查询不加分页的方法请求    
        //     this.$axios.post("http://localhost:8082/medbuy/buySearch", this.medbuy)
        //         .then((result) => {
        //             let vo = result.data;
        //             if (vo.code == 200) {
        //                 this.medbuyList = vo.data;
        //             }
        //         }).catch((err) => {
        //             console.log(err);
        //         });
        // },


        reset() {  //查询框的内容重置
            this.medbuy = {};
            this.list(); 
        },

        //分页配置
        handleSizeChange(val) {
            this.pageInfo.pageSize = val;
            this.list()
        },
        handleCurrentChange(val) {
            this.pageInfo.pageNum = val;
            this.list()
        },

        list() {   //列表，列表分页，查询，查询分页都在一个请求中
            this.$axios.post("/medbuy/buySearch?pageNum=" + this.pageInfo.pageNum + "&pageSize=" + this.pageInfo.pageSize,this.medbuy)
                .then((result) => {
                    let vo = result.data;
                    if (vo.code == 200) {
                        this.medbuyList = vo.data.list;
                        this.pageInfo = vo.data;
                    }
                }).catch((err) => {
                    console.log(err);
                });

        }
    }
};
</script>